package Verifier.ByteTree;

/**
 * This class represents either a node or a leaf
 * @author ofekp
 */
public abstract class ByteTreeElement {

	ByteTreeElement parent;
	
	/**
	 * @param parent the parent of this element
	 */
	// validity: the data size in bytes is the data string length divided by 2
	public ByteTreeElement(Node parent) {
		this.parent = parent;
	}
	
	/**
	 * @return true if this is a leaf and false if node
	 */
	public abstract Boolean isLeaf();
	
	/**
	 * @return 	if leaf - the number of bytes in data is returned
	 * 			if node - the number children is returned
	 */
	public abstract int getDataLength();
	
	/**
	 * @return 	the byte string representation of this leaf or node
	 * 			if node - recursively concatenate answers from children 
	 */
	public abstract String toByteString();
	
	/**
	 * This function will set the parent of this node/leaf to be the requested
	 * parent.
	 * 
	 * @param parent the new parent of the ByteTreeElement
	 */
	public void setParent(Node parent) {
		this.parent = parent;
	}
	
	/**
	 * This function will create a 8 hex char string from the number that was
	 * inserted after it is converted to is hex representation.
	 * @param num a number
	 * @return 	the string that represent that number in hex
	 * 			the length of the string is 8 chars
	 */
	public String numTo8Char(int num) {
		String res = "";
		res = Integer.toHexString(num);
		int len = res.length();
		for (int i = 0; i < (8 - len); i++) {
			res = "0" + res;
		}
		return res;
	}
	
}
